package cn.web.base.activemq;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.*;

@Component
public class MessageAnnotationListener {

	@JmsListener(destination = "defaultQueue", containerFactory = "queueJmsListenerContainerFactory")
	public void onMessage(Message message) {
		if (message instanceof TextMessage) {
			TextMessage textMsg = (TextMessage) message;
			System.out.println("当前线程ID:" + Thread.currentThread().getId() + ":接收到一个TextMessage对象");
			try {
				System.out.println("消息内容是：" + textMsg.getText());
			} catch (JMSException e) {
				e.printStackTrace();
			}
		} else if (message instanceof ObjectMessage) {
			ObjectMessage objectMessage = (ObjectMessage) message;
			System.out.println("当前线程ID:" + Thread.currentThread().getId() + ":接收到一个ObjectMessage对象");
		} else if (message instanceof MapMessage) {
			MapMessage mapMessage = (MapMessage) message;
			System.out.println("当前线程ID:" + Thread.currentThread().getId() + ":接收到一个MapMessage对象");
		} else if (message instanceof BytesMessage) {
			BytesMessage bytesMessage = (BytesMessage) message;
			System.out.println("当前线程ID:" + Thread.currentThread().getId() + ":接收到一个BytesMessage对象");
		} else if (message instanceof StreamMessage) {
			StreamMessage streamMessage = (StreamMessage) message;
			System.out.println("当前线程ID:" + Thread.currentThread().getId() + ":接收到一个StreamMessage对象");

		}
	}
}
